package com.lzy.huijinjiazu.mvp.ui.adapter;

import android.graphics.Paint;
import android.text.Html;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.utils.ArmsUtils;
import com.lzy.huijinjiazu.R;
import com.lzy.huijinjiazu.mvp.model.entity.ShoppingCart;

/**
 * Created by long on 2018/1/15.
 */

public class ShoppingCartAdapter extends BaseQuickAdapter<ShoppingCart, BaseViewHolder> {
    private OnCheckClickListener mOnCheckClickListener;

    public void setOnCheckClickListener(OnCheckClickListener listener) {
        this.mOnCheckClickListener = listener;
    }

    public ShoppingCartAdapter() {
        super(R.layout.item_shopping_cart);
    }

    @Override
    protected void convert(BaseViewHolder helper, ShoppingCart item) {
        TextView tvOriginalPrice = helper.getView(R.id.tv_original_price);
        tvOriginalPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        TextView tvMoney = helper.getView(R.id.tv_moeny);
        tvMoney.setText(Html.fromHtml(ArmsUtils.getString(mContext, R.string.shopping_cart_money, "1000", "100")));
        LinearLayout llEdit = helper.getView(R.id.ll_edit);
        llEdit.setVisibility(item.isEdit() ? View.VISIBLE : View.GONE);
        CheckBox cbItem = helper.getView(R.id.cb_item);
        cbItem.setChecked(item.isCheck());
        cbItem.setOnClickListener(view -> {
            item.setCheck(cbItem.isChecked());
            mOnCheckClickListener.setOnItemClick(cbItem.isChecked(), cbItem);
        });
    }

    public interface OnCheckClickListener {
        void setOnItemClick(boolean isCheck, CheckBox view);

    }
}
